package com.sc.nft.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.dao.UserCreatorInfoDao;
import com.sc.nft.entity.dto.MallIncomeQueryDTO;
import com.sc.nft.entity.dto.MallIncomeQueryPageDTO;
import com.sc.nft.entity.dto.MallIncomeUpdateDTO;
import com.sc.nft.entity.vo.AdminUserCreatorInfoAllDao;
import com.sc.nft.entity.vo.MallIncomeVO;
import com.sc.nft.service.MallIncomeService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("admin/mallIncome")
@Api(tags = "订单收益模型")
public class MallIncomeController {

    private final MallIncomeService mallIncomeService;

    private final UserCreatorInfoDao userCreatorInfoDao;

    @ApiOperation(value = "修改指定DAO模板", notes = "修改指定DAO模板", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result update(@RequestBody MallIncomeUpdateDTO mallIncomeUpdateDTO) {
        mallIncomeService.update(mallIncomeUpdateDTO);
        return Result.success();
    }

    @ApiOperation(value = "删除指定DAO模板", notes = "删除指定DAO模板", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/deleteById", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result deleteById(@RequestBody IdRequest idRequest) {
        mallIncomeService.delete(idRequest.getId());
        return Result.success();
    }

    @ApiOperation(value = "指定ID获取数据", notes = "指定ID获取数据", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getById", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result getById(@RequestBody IdRequest idRequest) {
        return Result.success(mallIncomeService.get(idRequest.getId()));
    }

    @ApiOperation(value = "分页获取数据", notes = "分页获取数据", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/queryPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<Page<MallIncomeVO>> queryPage(@RequestBody MallIncomeQueryPageDTO mallIncomeQueryPageDTO) {
        return PageResult.success(mallIncomeService.queryPage(mallIncomeQueryPageDTO));
    }

    @ApiOperation(value = "获取数据", notes = "获取数据", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/query", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<MallIncomeVO>> query(@RequestBody MallIncomeQueryDTO mallIncomeQueryDTO) {
        return Result.success(mallIncomeService.query(mallIncomeQueryDTO));
    }

    @ApiOperation(value = "初始化", notes = "初始化", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/initialize", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiIgnore
    public Result initialize() {
        List<AdminUserCreatorInfoAllDao> all = userCreatorInfoDao.getAll();
        all.forEach(adminUserCreatorInfoAllDao -> {
            mallIncomeService.add(adminUserCreatorInfoAllDao.getId());
        });
        return Result.success();
    }

}
